package com.example.demo.service;

import com.example.demo.mapper.LoveMusicMapper;
import com.example.demo.model.Music;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoveMusicService {
    @Autowired
    private LoveMusicMapper loveMusicMapper;

//    查询该音乐是否 之前收藏过
    public Music findLoveMusicByMusicIdAndUserId(@Param("userid") Integer userid, @Param("musicid") Integer musicid) {
        return loveMusicMapper.findLoveMusicByMusicIdAndUserId(userid, musicid);
    }

//    收藏音乐  先数据表lovemusic中加入数据
    public boolean insertLoveMusic(@Param("userid") Integer userid, @Param("musicid") Integer musicid) {
        return loveMusicMapper.insertLoveMusic(userid, musicid);
    }



    // 如果没传入歌曲名/字符参数 那么就
    // 显示当前用户收藏的所有音乐
    public List<Music> findLoveMusicByKeyAndUserId(@Param("user_id") Integer user_id) {
        return loveMusicMapper.findLoveMusicByKeyAndUserId(user_id);
    }
    // 如果有传入歌曲名/字符参数 那么就进行模糊查询
    // 这里需要使用到多表查询
    public List<Music> findLoveMusicByKeyAndUserId(@Param("title") String title, @Param("user_id") Integer user_id) {
        return loveMusicMapper.findLoveMusicByKeyAndUserId(title,user_id);
    }
    // 取消收藏
    public Integer deleteLoveMusic(@Param("user_id") Integer user_id, @Param("user_id") Integer music_id) {
        return loveMusicMapper.deleteLoveMusic(user_id,music_id);
    }
}
